package com.itheima.job3;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        //创建SeverSocket对象设置服务端的端口号
        ServerSocket server = new ServerSocket(6666);
        //通过accept获取socket套字节与客户端建立连接
        while(true){
            Socket accept = server.accept();
                try {
                    InputStream is = accept.getInputStream();
                    Thread.sleep(200);
                    FileOutputStream fos = new FileOutputStream("E:/test/file/"+System.currentTimeMillis()+".txt");
                    byte[] buf = new byte[1024];//一次读取一个字节
                    int len;
                    while((len=is.read(buf))!=-1){
                        fos.write(buf,0,len);
                    }
                    fos.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

        }
        //
    }
}
